Skip to content

attestation crate: Add builder pattern for constructing AttestationVerifier - #70

Merged
ameba23 merged 10 commits into
mainfrom
peg/attestation-verifier-builder
Aug 27, 2026
Merged

attestation crate: Add builder pattern for constructing AttestationVerifier#70
ameba23 merged 10 commits into
mainfrom
peg/attestation-verifier-builder

Conversation

@ameba23

@ameba23 ameba23 commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

This is a library API breaking change.

This adds a builder pattern for constructing AttestationVerifier. It removes the old constructor and makes several fields private which were public before, so it breaks the API.

@ameba23
ameba23 force-pushed the peg/attestation-verifier-builder branch from ddfdb7b to ecfa3b7 Compare August 25, 2026 09:02
@ameba23
ameba23 force-pushed the peg/attestation-verifier-builder branch from ecfa3b7 to 6dc3123 Compare August 25, 2026 09:38

@samlaf samlaf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving comments, as requested in #84 (comment)

Comment thread crates/attestation-provider-server/src/main.rs Outdated
Comment thread crates/attestation/src/lib.rs Outdated
Comment thread crates/attestation/src/lib.rs Outdated
Comment thread crates/attestation/src/lib.rs Outdated
Comment on lines +399 to +417
/// Keep a DCAP collateral cache, and pre-fill it with all available
/// collateral
pub fn with_pccs_prewarmed(mut self) -> Self {
self.internal_pccs_prewarm = Some(true);
self
}

/// Keep a DCAP collateral cache, starting empty
pub fn with_pccs_not_prewarmed(mut self) -> Self {
self.internal_pccs_prewarm = Some(false);
self
}

/// Set the URL used by internal PCCS
pub fn pccs_url(mut self, pccs_url: String) -> Self {
self.pccs_url = Some(pccs_url);
self
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these pccs functions are a bit confusing. Didn't understand the difference between internal_pccs_prewarm = None and Some(false) at first... and then having pccs_url and internal_pccs_prewarm separate is kind of weird and even allows a combination that is nonsense (passing a url but setting prewarm to None).

How about refactoring into an enum instead?

  /// How the verifier obtains DCAP collateral
  #[derive(Clone, Debug)]
  pub enum PccsMode {
      /// No internal collateral cache. DCAP/Azure verification returns
      /// [AttestationError::NoPccs].
      None,
      /// Internal cache pre-filled with all available collateral at build
      /// time. `url` defaults to Intel PCS.
      Prewarmed { url: Option<String> },
      /// Internal cache that starts empty and fetches on demand.
      /// `url` defaults to Intel PCS.
      Lazy { url: Option<String> },
  }

then you can do something like:

  AttestationVerifier::builder(policy)
      .with_pccs(PccsMode::Prewarmed { url: cli.pccs_url })
      .with_dump_dcap_quotes(cli.log_dcap_quote)
      .build()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, agree this is better. Did this, but did not put the url in because we also need the URL in the 'none' case. In the async version of the verifier, no pccs mean it will always use the remote service (given url or intel pcs) on every verification.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice! Think this is starting to make more sense to me. Then I'd consider renaming PccsMode to CollateralCache or PccsCache something. CollateralCache::None is a lot more explicit about what its doing.

Also looks like there's a bug since in the None case the pccs_url is not being used and it always defaults to intel.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also found a related issue while reviewing this, created #87

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also looks like there's a bug since in the None case the pccs_url is not being used and it always defaults to intel.

Good catch. I ended up doing quite a big refactor to address this - see: Also looks like there's a bug since in the None case the pccs_url is not being used and it always defaults to intel.

Comment thread crates/attestation/src/lib.rs Outdated
…ts/attested-tls into peg/attestation-verifier-builder

* 'peg/attestation-verifier-builder' of github.com:flashbots/attested-tls:
  Add builder pattern for constructing AttestationVerifier
  Add builder pattern for constructing AttestationVerifier
  Run clippy on stable in CI to avoid issue with it failing with dependencies
@ameba23
ameba23 requested a review from samlaf August 26, 2026 06:59

@samlaf samlaf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM outside of the fix below and the ongoing discussion above

Comment thread crates/attestation/src/lib.rs
Co-authored-by: Samuel Laferriere <9342524+samlaf@users.noreply.github.com>
@ameba23
ameba23 merged commit 2303154 into main Aug 27, 2026
4 checks passed
@ameba23
ameba23 deleted the peg/attestation-verifier-builder branch August 27, 2026 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants